import requests
from bs4 import BeautifulSoup

class Douban:

    def __init__(self):
        self.URL = 'https://movie.douban.com/top250'
        self.starnum = []
        for starnum in range(0, 51, 25):
            self.starnum.append(starnum)
        self.header = { 'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36' }

    def get_top250(self):
        for start in self.starnum:
            start = str(start)
            html = requests.get(self.URL, params = {'getdata': start}, headers = self.header)

            soup = BeautifulSoup(html.text, "html.parser")

            #print(soup.get_text())

            name = soup.select('#content > div > div.article > ol > li > div > div.info > div.hd > a > span:nth-child(1)')

            for name in name:
                print(name.get_text())

if __name__ == "__main__":
    cls = Douban()
    cls.get_top250()